﻿using UnityEngine;
using System.Collections;

public class BirdCommon : MonoBehaviour
{
    Rigidbody2D birdRigidbody2D;
    [SerializeField]
    float m_Speed;
    bool isHit = false;
    bool isRecircling = false;
    private void Awake()
    {
        birdRigidbody2D = GetComponent<Rigidbody2D>();
    }
    private void OnEnable()
    {
        isHit = false;
        isRecircling = false;
        birdRigidbody2D.gravityScale = 0f;
        birdRigidbody2D.velocity = transform.right * m_Speed;
    }
    IEnumerator RecoverBird()
    {
        yield return new WaitForSeconds(20f);
        if(!isRecircling)
        {
            ObjectPoolManager.Instance.RecircleCommonBird(this);
            isRecircling = true;
        }
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (!isHit && collision.transform.CompareTag(Constants.Text_Tag_Wall) || collision.transform.CompareTag(Constants.Text_Tag_Stone))
        {
            isHit = true;
            birdRigidbody2D.gravityScale = 1f;
            if (!isRecircling)
            {
                ObjectPoolManager.Instance.RecircleCommonBird(this);
                isRecircling = true;
            }
        }
    }
}
